package com.jz.community.moduleshoppingguide.home.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.glideConfig.GlideApp;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.RoundCornersTransformation;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.home.bean.HomeFindBean;

import java.util.List;


public class HomeMainActPinGoodsAdapter extends BaseQuickAdapter<HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean.ActivityGoodsBean, BaseViewHolder> {

    public HomeMainActPinGoodsAdapter(int layoutResId, @Nullable List<HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean.ActivityGoodsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeFindBean.EmbeddedBean.ContentBean.ChunnelHomePageBean.ActivityGoodsBean entity) {


        LinearLayout goods_parent = helper.getView(R.id.home_act_pin_parent);

        ImageView imageView = helper.getView(R.id.home_act_pin_img);

        ViewGroup.LayoutParams lp1 = goods_parent.getLayoutParams();

        int parent_width = ((SHelper.getScrrenWidth((Activity) mContext) - SHelper.dp2px(mContext, 45)) / 13) * 4;
        lp1.width = parent_width;
        goods_parent.setLayoutParams(lp1);

        ViewGroup.LayoutParams lp_img = imageView.getLayoutParams();

        lp_img.width = parent_width;
        lp_img.height = parent_width;
        imageView.setLayoutParams(lp_img);
        RoundCornersTransformation transformation = new RoundCornersTransformation(mContext,
                SHelper.dp2px(mContext, 5), RoundCornersTransformation.CornerType.ALL);
        GlideApp.with(mContext)
                .load(entity.getImages())
                .transform(transformation)
                .placeholder(R.mipmap.image_default)
                .error(R.mipmap.image_default)
                .into(imageView);

        helper.setText(R.id.home_act_pin_name, entity.getTitle());

        //原价
        String price = entity.getPrice();
        TextView price_red = helper.getView(R.id.home_act_pin_red);

        //活动价格
        String limit_price = entity.getDiscountPrice();
        TextView price_gray = helper.getView(R.id.home_act_pin_gray);


        if (!TextUtils.isEmpty(limit_price)) {
            price_gray.setVisibility(View.VISIBLE);
            price_red.setText(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(limit_price)));
            RxTextTool.getBuilder("")
                    .append("¥" + CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(price)))
                    .setStrikethrough()
                    .into(price_gray);
        } else {
            price_gray.setVisibility(View.GONE);
            price_red.setText(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(price)));
        }

    }
}
